package com.isnmp.common.base;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;


public class FileUtil {
    private static byte[] data = null;

    public static byte[] readFile2(String paramString) throws IOException {
        File localFile = new File(paramString);
        long l = localFile.length();
        byte[] arrayOfByte = new byte[(int) l];
        FileInputStream localFileInputStream = new FileInputStream(localFile);
        int i = localFileInputStream.read(arrayOfByte);
        if (i != l)
            throw new IOException("Only read " + i + " of " + l + " for " + localFile);
        localFileInputStream.close();
        return arrayOfByte;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static byte[] readFile(String paramString) throws IOException {
        ArrayList localArrayList = new ArrayList();
        try {
            Object localObject = FileUtil.class.getClassLoader().getResource(paramString).openStream();
            byte[] arrayOfByte = new byte[1];
            while (-1 != ((InputStream) localObject).read(arrayOfByte)) {
                localArrayList.add(Byte.valueOf(arrayOfByte[0]));
            }
            ((InputStream) localObject).close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        byte[] bytes = new byte[localArrayList.size()];
        for (int i = 0; i < localArrayList.size(); i++) {
            bytes[i] = ((Byte) localArrayList.get(i)).byteValue();

        }
        System.out.println("bytes==" + bytes.toString());
        return bytes;
    }


    public static void writeFile(String paramString, byte[] paramArrayOfByte) throws IOException {
        FileOutputStream localFileOutputStream = new FileOutputStream(paramString);
        localFileOutputStream.write(paramArrayOfByte);
        localFileOutputStream.close();
    }
}